package com.ha.web.controller.system.promote.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ha.common.annotation.Log;
import com.ha.common.enums.BusinessType;
import com.ha.system.promote.domain.HaHousePromote;
import com.ha.system.promote.service.IHaHousePromoteService;
import com.ha.common.core.controller.BaseController;
import com.ha.common.core.domain.AjaxResult;
import com.ha.common.utils.poi.ExcelUtil;
import com.ha.common.core.page.TableDataInfo;

/**
 * 好房推荐Controller
 * 
 * @author admin
 * @date 2021-03-16
 */
@Controller
@RequestMapping("/promote/promote")
public class HaHousePromoteController extends BaseController
{
    private String prefix = "promote/promote";

    @Autowired
    private IHaHousePromoteService haHousePromoteService;

    @RequiresPermissions("promote:promote:view")
    @GetMapping()
    public String promote()
    {
        return prefix + "/promote";
    }

    /**
     * 查询好房推荐列表
     */
    @RequiresPermissions("promote:promote:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(HaHousePromote haHousePromote)
    {
        startPage();
        List<HaHousePromote> list = haHousePromoteService.selectHaHousePromoteList(haHousePromote);
        return getDataTable(list);
    }

    /**
     * 导出好房推荐列表
     */
    @RequiresPermissions("promote:promote:export")
    @Log(title = "好房推荐", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(HaHousePromote haHousePromote)
    {
        List<HaHousePromote> list = haHousePromoteService.selectHaHousePromoteList(haHousePromote);
        ExcelUtil<HaHousePromote> util = new ExcelUtil<HaHousePromote>(HaHousePromote.class);
        return util.exportExcel(list, "promote");
    }

    /**
     * 新增好房推荐
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存好房推荐
     */
    @RequiresPermissions("promote:promote:add")
    @Log(title = "好房推荐", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(HaHousePromote haHousePromote)
    {
        return toAjax(haHousePromoteService.insertHaHousePromote(haHousePromote));
    }

    /**
     * 修改好房推荐
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        HaHousePromote haHousePromote = haHousePromoteService.selectHaHousePromoteById(id);
        mmap.put("haHousePromote", haHousePromote);
        return prefix + "/edit";
    }

    /**
     * 修改保存好房推荐
     */
    @RequiresPermissions("promote:promote:edit")
    @Log(title = "好房推荐", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(HaHousePromote haHousePromote)
    {
        return toAjax(haHousePromoteService.updateHaHousePromote(haHousePromote));
    }

    /**
     * 删除好房推荐
     */
    @RequiresPermissions("promote:promote:remove")
    @Log(title = "好房推荐", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(haHousePromoteService.deleteHaHousePromoteByIds(ids));
    }
}
